package com.mida.bms.report;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.apache.commons.collections4.CollectionUtils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@JacksonStdImpl
@SuppressWarnings("serial")
public class LongArray2StringSerialize extends StdSerializer<List>{

	public final static LongArray2StringSerialize instance = new LongArray2StringSerialize();
	protected LongArray2StringSerialize(Class<?> t, boolean dummy) {
		super(t, dummy);
		// TODO Auto-generated constructor stub
	}
	public LongArray2StringSerialize() {
		super(List.class);
	}
	@Override
	public void serialize(List value, JsonGenerator gen, SerializerProvider provider) throws IOException {
		if(CollectionUtils.isEmpty(value)) gen.writeObject(value);
		else {
			List<String> vl = new ArrayList<String>(value.size());
			for (Object st : value) {
				vl.add(String.valueOf(st));
			}
			gen.writeObject(vl);
		}

	}


}
